package com.hongyue.zuoTi;

import java.math.BigDecimal;

import static java.math.BigDecimal.ROUND_HALF_UP;

/*
	有以下double数组：
		double[] arr = {0.1,0.2,2.1,3.2,5.56,7.21};
	请编程计算它们的总值及平均值(四舍五入保留小数点后2位)
 */
public class Demo {
    public static void main(String[] args) {
        double[] arr = {0.1,0.2,2.1,3.2,5.56,7.21};
        double a = 0;
        for (int i = 0; i < arr.length; i++) {
            a += arr[i];
        }
        BigDecimal bd = new BigDecimal(a + "");
        BigDecimal divide = bd.divide(new BigDecimal(arr.length), 2, ROUND_HALF_UP);
        System.out.println(divide);
    }
}
